main(n,i,o,j,b){char a[24];for(gets(a);gets(a);){i=0;i+=*a==73?3:4;a[i-1]=0;if(*a==a[i])puts(a);else{for(n=o=j=0;j++<6;b==3?n++:o++,i+=b)b=a[i]==73?3:4;puts(n!=o?(n>o?"IN":"OUT"):"AGAIN");}}}
